<?php

namespace App\Http\Requests\Home;

use Illuminate\Foundation\Http\FormRequest;

class UserRegister extends FormRequest
{
    /**
     * Determine if the user is authorized to make this request.
     *
     * @return bool
     */
    public function authorize()
    {
        return true;
    }

    /**
     * Get the validation rules that apply to the request.
     *
     * @return array
     */
    public function rules()
    {
        return [
            'name'      => 'required|min:6|max:20|alpha_dash',
            'email'     => 'required|email',
            'phone'     =>[
                            'required',
                            'regex:/^1(3[0-9]|4[57]|5[0-35-9]|7[0135678]|8[0-9])\\d{8}$/',
            ],
            'phonecode' => 'required',
            'code'      => 'required',
            'pwd'       => 'required|min:6|max:20|alpha_dash',
            'confirmPwd'=> 'required|min:6|max:20|alpha_dash',
            'agree'     => 'required',
        ];
    }

    public function messages()
    {
         return [
            'name.required'  => '请输入用户名',
            'name.min'       =>  '用户名最少6个字符',
            'name.max'       =>  '用户名最多20个字符',
            'name.alpha_dash'=> '请用字母、数字、破折号（ - ）以及下划线（ _ ）',

            'email.required' => '请输入邮箱',
            'email.email'    => '邮箱不合法',

            'phone.required' => '请输入手机号码',
            'phone.regex'    => '手机号不合法',

            'phonecode.required'=> '请输入手机验证码',

            'code.required'     => '请输入验证码',

            'pwd.required'      => '请输入密码',
            'pwd.min'           => '密码最少6个字符',
            'pwd.max'           => '密码最多20个字符',
            'pwd.alpha_dash'    => '请用字母、数字、破折号（ - ）以及下划线（ _ ）',

            'confirmPwd.required'    => '请输入确认密码',
            'confirmPwd.min'         => '密码最少6个字符',
            'confirmPwd.max'         => '密码最多20个字符',
            'confirmPwd.alpha_dash'  => '请用字母、数字、破折号（ - ）以及下划线（ _ ）',
            
            'agree.required'         => '请浏览服务协议',
        ];
    }
}
